﻿<UserControl x:Class="PurchaseSales.Manage.Views.SalesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
    <UserControl.Resources>
        <ContextMenu x:Key="RowMenu" DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
            <MenuItem Header="删除" Command="{Binding DataContext.DeletedCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" Background="{x:Null}" CommandParameter="{Binding}"/>
        </ContextMenu>
    </UserControl.Resources>
    <TabControl>
        <TabItem Header="销售商品">
            <Grid>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="VisualStateGroup">
                        <VisualStateGroup.Transitions>
                            <VisualTransition>
                                <Storyboard>

                                </Storyboard>
                            </VisualTransition>
                        </VisualStateGroup.Transitions>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="225"/>
                    <ColumnDefinition Width="225"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <TextBlock Text="客户列表"  FontSize="18" FontFamily="Microsoft YaHei"/>
                <ListBox x:Name="CustomerList" Grid.Row="1" ItemsSource="{Binding Customers}" 
                         Background="Gray" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                    <ListBox.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </ListBox.RenderTransform>
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="SnapsToDevicePixels" Value="true"/>
                            <Setter Property="OverridesDefaultStyle" Value="true"/>
                            <Setter Property="VerticalContentAlignment" Value="Top"/>
                            <Setter Property="HorizontalContentAlignment" Value="Left"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Grid SnapsToDevicePixels="true" Margin="5" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                                            <ContentPresenter/>
                                            <Border  x:Name="Checked" BorderThickness="3" BorderBrush="#FF41B1E1">
                                                <Grid>
                                                    <Path Width="33" Height="33" Stretch="Fill"  HorizontalAlignment="Right" VerticalAlignment="Top"  Fill="#FF41B1E1" Data="F1 M 294.469,237.943L 307.781,237.943L 307.781,250.276"/>
                                                    <Path Width="16" Height="14" Fill="White"  Data="F1 M 263.89,239.418L 265.043,240.571L 267.402,238.212L 267.912,238.722L 265.553,241.081L 265.553,241.081L 265.043,241.591L 265.043,241.591L 264.533,241.081L 263.38,239.928L 263.89,239.418 Z " 
                                       HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="Fill" Margin="0,1,1,0"/>
                                                </Grid>
                                            </Border>
                                            <ToolTipService.ToolTip>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="供应商名称：" VerticalAlignment="Center"/>
                                                    <TextBlock Text="{Binding Name}"   VerticalAlignment="Center"/>
                                                </StackPanel>
                                            </ToolTipService.ToolTip>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsSelected" Value="true">
                                                <Setter TargetName="Checked" Property="Visibility" Value="Visible"/>
                                            </Trigger>
                                            <Trigger Property="IsSelected" Value="false">
                                                <Setter TargetName="Checked" Property="Visibility" Value="Hidden"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
					VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border Background="White" HorizontalAlignment="Left" VerticalAlignment="Top" Height="80" Width="100"
                            Padding="5">
                                <TextBlock Text="{Binding Name}" FontSize="18" VerticalAlignment="Bottom"/>
                            </Border>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction Command="{Binding SelectedCustomerCommand}" 
                                           CommandParameter="{Binding ElementName=CustomerList, Path=SelectedItem}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </ListBox>

                <TextBlock Text="产品列表"  FontSize="18" Grid.Column="1" FontFamily="Microsoft YaHei"/>

                <ListBox x:Name="CommodityList" Grid.Row="1" ItemsSource="{Binding Commodities}" Background="Gray" Grid.Column="1"
                         ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                    <ListBox.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </ListBox.RenderTransform>
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="SnapsToDevicePixels" Value="true"/>
                            <Setter Property="OverridesDefaultStyle" Value="true"/>
                            <Setter Property="VerticalContentAlignment" Value="Top"/>
                            <Setter Property="HorizontalContentAlignment" Value="Left"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Grid SnapsToDevicePixels="true" Margin="5" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                                            <ContentPresenter/>
                                            <Border  x:Name="Checked" BorderThickness="3" BorderBrush="#FF41B1E1">
                                                <Grid>
                                                    <Path Width="33" Height="33" Stretch="Fill"  HorizontalAlignment="Right" VerticalAlignment="Top"  Fill="#FF41B1E1" Data="F1 M 294.469,237.943L 307.781,237.943L 307.781,250.276"/>
                                                    <Path Width="16" Height="14" Fill="White"  Data="F1 M 263.89,239.418L 265.043,240.571L 267.402,238.212L 267.912,238.722L 265.553,241.081L 265.553,241.081L 265.043,241.591L 265.043,241.591L 264.533,241.081L 263.38,239.928L 263.89,239.418 Z " 
                                       HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="Fill" Margin="0,1,1,0"/>
                                                </Grid>
                                            </Border>
                                            <ToolTipService.ToolTip>
                                                <Grid>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition/>
                                                        <RowDefinition/>
                                                    </Grid.RowDefinitions>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition/>
                                                        <ColumnDefinition/>
                                                    </Grid.ColumnDefinitions>
                                                    <TextBlock Text="产品名称：" VerticalAlignment="Center"/>
                                                    <TextBlock Text="产品类型" Grid.Row="1" VerticalAlignment="Center"/>

                                                    <TextBlock Text="{Binding Name}" Grid.Column="1" VerticalAlignment="Center"/>
                                                    <TextBlock Text="{Binding CommodityType}" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center"/>
                                                </Grid>
                                            </ToolTipService.ToolTip>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsSelected" Value="true">
                                                <Setter TargetName="Checked" Property="Visibility" Value="Visible"/>
                                            </Trigger>
                                            <Trigger Property="IsSelected" Value="false">
                                                <Setter TargetName="Checked" Property="Visibility" Value="Hidden"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
					VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border Background="White" HorizontalAlignment="Left" VerticalAlignment="Top" Height="80" Width="100"
                            Padding="5">
                                <TextBlock Text="{Binding Name}" FontSize="18" VerticalAlignment="Bottom"/>
                            </Border>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction Command="{Binding SelectedCommodityCommand}" 
                                           CommandParameter="{Binding ElementName=CommodityList, Path=SelectedItem}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </ListBox>

                <GridSplitter Grid.Column="1" HorizontalAlignment="Left" Grid.RowSpan="3" VerticalAlignment="Center" Style="{StaticResource VerticalGridSplitterStyle}" />

                <GroupBox Grid.Column="2" Grid.Row="1">
                    <StackPanel>
                        <TextBlock Text="销售编号"/>
                        <TextBox Text="{Binding Number, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                        <TextBlock Text="剩余数量"/>
                        <TextBox Text="{Binding RemainCount}" IsReadOnly="True"/>
                        <TextBlock Text="购买数量"/>
                        <TextBox Text="{Binding BuyCount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                        <TextBlock Text="备注"/>
                        <TextBox Text="{Binding Remark, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Height="50"/>
                    </StackPanel>
                </GroupBox>

                <Button Grid.Row="2" Grid.Column="2" Content="Add" Width="80" Margin="0 10" HorizontalAlignment="Right"
                        Command="{Binding AddCommand}"/>
            </Grid>
        </TabItem>
        <TabItem Header="销售详细单">
            <Grid>
                <DataGrid x:Name="Element_Purchase" ItemsSource="{Binding Saleses}" IsReadOnly="True" AutoGenerateColumns="False" >
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="销售编号" Binding="{Binding Number}" Width="*"/>
                        <DataGridTextColumn Header="商品名称" Binding="{Binding Commodity.Name}" Width="*"/>
                        <DataGridTextColumn Header="客户名称" Binding="{Binding Customer.Name}" Width="*"/>
                        <DataGridTextColumn Header="销售日期" Binding="{Binding SaleDate, StringFormat=yyyy/MM/dd}" Width="*"/>
                        <DataGridTextColumn Header="商品单价" Binding="{Binding Commodity.PresalePrice}" Width="*"/>
                        <DataGridTextColumn Header="销售数量" Binding="{Binding Count}" Width="*"/>
                        <DataGridTextColumn Header="总价" Binding="{Binding TotalPrice}" Width="*"/>
                    </DataGrid.Columns>
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <Setter Property="ContextMenu" Value="{StaticResource RowMenu}"/>
                        </Style>
                    </DataGrid.RowStyle>
                </DataGrid>
            </Grid>
        </TabItem>
    </TabControl>
</UserControl>
